package com.sdgakj.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.annotation.Transient;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Entity
@Table(name="f_permission")
public class Permission implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	/**id自增*/
	private Long id;
	/**权限名称*/
	private String name;
	/**类型：按钮，菜单*/
	private String type;
	/**父级菜单*/
	private Permission parent;
	/**从根到父级的全部路径*/
	private String parentids;
	/**权限的标识，jsp上用*/
	private String permissionname;
	/**动态菜单使用，暂时不用*/
	private String url;	
	/**是否可用按钮*/
	private String deltag;
	/**日期按钮*/
	private Date createdate;
	/**权限子项*/
	private List<Permission> children;
	
	public Permission() {

	}
	
	public Permission(Long id) {
		this.id = id;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}


	public String getParentids() {
		return parentids;
	}

	public void setParentids(String parentids) {
		this.parentids = parentids;
	}

	public String getPermissionname() {
		return permissionname;
	}

	public void setPermissionname(String permissionname) {
		this.permissionname = permissionname;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getDeltag() {
		return deltag;
	}

	public void setDeltag(String deltag) {
		this.deltag = deltag;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="pid")
	@JsonIgnore
	@JSONField(serialize=false)
	public Permission getParent() {
		return parent;
	}

	public void setParent(Permission parent) {
		this.parent = parent;
	}

	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name="pid")
	@Transient
	public List<Permission> getChildren() {
		return children;
	}

	public void setChildren(List<Permission> children) {
		this.children = children;
	}
	
}
